package com.example.manager.controller;

import com.example.manager.utils.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "文件管理")
@RestController
@RequestMapping(value = "/admin/system/file")
public class FileController {


    @Autowired
    private MinioUtil minioUtil;
    @Value("${minio.endpointUrl}")
    private String address;
    @Value("${minio.bucketName}")
    private String bucketName;

    @ApiOperation(value = "上传文件")
    @PostMapping("/upload")
    @ApiImplicitParam(name = "token" ,value = "token值"  ,dataType = "String",paramType = "header")
    public String upload(MultipartFile file) {
        minioUtil.existBucket(bucketName);
        List<String> upload = minioUtil.upload(new MultipartFile[]{file});
        return address+"/"+bucketName+"/"+upload.get(0);
    }


}
